perm filename FLAT.LSP[206,LSP] blob
sn#381634 filedate 1978-09-18 generic text, type T, neo UTF8
;;; derived functions for flat and fringe
(defprop flat
(flat cflat dflat rflat tflat gflat gflat2 fringe cfringe append cappend)
flatfns)
(defun flat (x u) (cond ((atom x) (cons x u))
(t (flat (car x) (flat (cdr x) u)))))
(defun cflat (x u) (cond ((atom x) 1)
(t (plus (cflat (car x) (flat (cdr x) u)) (cflat (cdr x) u)))))
(defun dflat (x u) (cond ((atom x) 0)
(t (max (dflat (car x) (flat (cdr x) u)) (plus 1 (dflat (cdr x) u))))))
(defun rflat (x u) (cond ((atom x) 1)
(t (plus 1 (rflat (car x) (flat (cdr x) u)) (rflat (cdr x) u)))))
(defun tflat (x u) (cond ((atom x) (list (list x u (flat x u))))
(t (cons (list x u (flat x u)) (append (tflat (cdr x) u) (tflat
(car x) (flat (cdr x) u)))))))
(defun gflat (x u g h) (cond ((atom x) (g x u))
(t (h (gflat (car x) (flat (cdr x) u) g h) (gflat (cdr x) u) x u))))
(defun gflat2 (x u v g h) (cond ((atom x) (g x u v))
(t (gflat2 (car x) (flat (cdr x) u) (h (gflat2 (cdr x) u v g h) x u v) g h))))
(defun fringe (x) (cond ((atom x) (cons x nil))
(t (append (fringe (car x)) (fringe (cdr x))))))
(defun cfringe (x) (cond ((atom x) 1)
(t (plus (cappend (fringe car x) (fringe cdr x)) (cfringe car x) (cfringe cdr x)))))
(defun append (u v) (cond ((null u) v)
(t (cons (car u) (append (cdr u) v)))))
(defun cappend (u v) (cond ((null u) 0)
(t (plus 1 (cappend (cdr u) v)))))